<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../film-assets/js/common.js"></script>
    <link rel="stylesheet" href="../film-assets/css/base.css">
    <link rel="stylesheet" href="../../assets/font/iconfont.css">
    <link rel="stylesheet" href="./util/vue-message.css">
</head>
<body>
    <!-- 
        因为vue的组件化构建语法定义的组件，是需要运行vue语法环境的，
        所以任何vue项目都必然存在一个手动构建vue容器和实例，该容器和实例被叫做应用实例和容器，
        也被叫做根容器 Root
    -->
    <!-- 
        vue对组件名称和文件构建存在一个约定的要求：
            + 组件名和组件文件名一定以多个单词方式组成(除Root,App,内置组件)，采用大驼峰规则名称 
                => 规避和HTML标签名称的冲突
    -->
    <div id="app" class="app">
        <nav-bar></nav-bar>
        <div class="content-box">
            <div class="home-box">
                <!-- 首页分类列表 start -->
                <div v-for="t in types" :key="t.typeId">
                    <div class="list-name">
                        <span>{{ t.typeName }}</span>
                        <span class="list-more">更多 > </span>
                    </div>
                    <!-- 组件标签上定义的class样式是可以直接传递给组件的唯一根元素 -->
                    <film-list class="list-content" :list="t.list"></film-list>
                </div>
            </div>
        </div>
    </div>

    <script src="../../assets/axios/axios.js"></script>
    <script type="module"> 
        import { createApp } from "../../assets/vue3/vue.esm-browser.js";
        import api from "./api/api.js"
        import message from "./util/vue-message.js"
        import NavBar from "./filmComponent/NavBar.js";
        import FilmList from "./filmComponent/FilmList.js";
        createApp({
            components: {
                NavBar,FilmList
            },
            data(){
                return {
                    types:[
                        
                    ]
                }
            },
            methods: {
                // async initHomeData() {
                //     let result = await this.$api.loadTypes();
                //     if(!result.state){
                //         this.$showTip("查无数据","","warning")
                //         return;
                //     }
                //     this.types = result.data;

                //     this.types.forEach( async (t) => {
                //         let filmResult = await this.$api.loadFilms({ tid:t.typeId })
                //         if(!filmResult.state){
                //             this.$showTip("查无数据","","warning")
                //             return;
                //         }
                //         t.list = filmResult.data
                //     });
                // }
                async initHomeData() {
                    let result = await this.$api.loadTypes();
                    if(!result.state){
                        this.$showTip("查无数据","","warning")
                        return;
                    }
                    
                    for (const t of result.data) {
                        let filmResult = await this.$api.loadFilms({ tid:t.typeId })
                        if(!filmResult.state){
                            this.$showTip("查无数据","","warning")
                            return;
                        }
                        t.list = filmResult.data;
                    }
                    this.types = result.data;
                }
            },
            created () {
                this.initHomeData();
            },
        })
        .use(api)
        .use(message)
        .mount("#app")
    </script>
</body>
</html>